﻿using MinistryManager.DataAccess.Services.ServiceInterfaces;
using MinistryManager.Util.Authentication;

namespace MinistryManager.Util.Helpers
{
    public class LoginHelper
    {
        private readonly IFormsAuthentication _formsAuthentication;
        private readonly IVolunteerService _volunteerService;

        public LoginHelper(IFormsAuthentication formsAuthentication, IVolunteerService volunteerService)
        {
            _formsAuthentication = formsAuthentication;
            _volunteerService = volunteerService;
        }

        public LoginHelper(IFormsAuthentication formsAuthentication)
        {
            _formsAuthentication = formsAuthentication;
        }

        public bool LoginUser(string username, string password)
        {
            var user = _volunteerService.GetUserByUserNameAndPassword(username, password);
            if (user == null)
            {
                return false;
            }

            _formsAuthentication.SetAuthenticationUser(username);
            return true;
        }
    }
}